<template>
	<view class="playlet-search">
		<u-navbar height="55" titleStyle="padding-left:0" bgColor="#080808" :placeholder="true">
			<view slot="left" style="width: 100vw;padding: 0 !important;" id="navSoltLeft">
				<view class="flex justify-between align-center" style="width: 100%; ">
					<view class="back" @click="goBack">
						<u-icon name="arrow-left" v-if="!serachShow" color="#fff" size="20"></u-icon>
						<u-icon name="close" v-else color="#fff" size="20"></u-icon>
					</view>
					<view class="flex-1 flex">
						<input class="uni-input" v-model="cateForm.title" :placeholder="$t('playlet.please')" />
						<view class="searchIcon" @click="handleSearch">
							<u-icon name="search" color="#fff" size="28"></u-icon>
						</view>
					</view>
					<view class="p-2 pr-3 right" @click="handleCateShow">
						<u-icon name="/static/playlet/cate.png" color="#fff" size="20"></u-icon>
						<!-- <u-icon color="#fff" size="22" name="bell"></u-icon> -->
					</view>
				</view>
			</view>
		</u-navbar>
		<view class="cate-list">
			<!-- :animation="animationData" -->
			<view class="cate" v-if="cateShow">
				<view class="item">
					<view class="all" @click="handleUpdatForm('vip','')" :class="cateForm.vip==''?'active':''">
						{{$t('playlet.all')}}
					</view>
					<view class="key">
						<view class="value" @click="handleUpdatForm('vip',item.value)"
							:class="cateForm.vip==item.value?'active':''" v-for="item in vipList" :key="item.value">
							{{item.key}}
						</view>
					</view>
				</view>
				<view class="item">
					<view class="all" @click="handleUpdatForm('sex','')" :class="cateForm.sex==''?'active':''">
						{{$t('playlet.all')}}
					</view>
					<view class="key">
						<view class="value" :class="cateForm.sex==item.value?'active':''" @click="
							handleUpdatForm('sex',item.value)" v-for="item in sexList" :key="item.value">
							{{item.key}}
						</view>
					</view>
				</view>
				<view class="item">
					<view class="all" @click="handleUpdatForm('type','')" :class="cateForm.type==''?'active':''">
						{{$t('playlet.all')}}
					</view>
					<view class="key">
						<view class="value" :class="cateForm.type==item.id?'active':''"
							@click=" handleUpdatForm('type',item.id)" v-for="item in cateList" :key="item.id">
							{{item.name}}
						</view>
					</view>
				</view>
				<view class="item">
					<view class="all" @click="handleUpdatForm('order','')" :class="cateForm.order==''?'active':''">
						{{$t('playlet.all')}}
					</view>
					<view class="key">
						<view class="value" :class="cateForm.order==item.value?'active':''" v-for="item in orderList"
							@click="handleUpdatForm('order',item.value)" :key="item.value">
							{{item.key}}
						</view>
					</view>
				</view>

			</view>
			<view class="cate-video" v-if="!serachShow">
				<view class="" v-if="skeletonShow">
					<view  class="video-item" v-for="(item,index) in 6"
						:style="{'margin-right':(index+1)%3==0?'0px':''}">
						<view class="image">
						</view>
						<view class="content">
							<view class="title">
							</view>
							<view class="desc">
							</view>
						</view>
					</view>
				</view>
				<view class="pt-5 empty" v-if="videoList.length==0">
					<u-empty :text="$t('public.nodata')" icon="/static/empty/nodata.png"></u-empty>
				</view>
				<view class="" v-else>
					<view class="video-item" @click="goShortInfo(item.id)" v-for="(item,index) in videoList"
						:style="{'margin-right':(index+1)%3==0?'0px':''}">
						<view class="image">
							<image class="img" :src="item.img" alt="" />
							<!-- <view class="episode">
								{{$t('playlet.episode')}} &nbsp;{{item.update_number}}/{{item.total}}
							</view> -->
							<view class="position-absolute bottom-0 left-0 right-0 flex align-center justify-end pr-1" style="height: 20px; background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.5) 100%);">
								<u-icon name="eye" color="#eeeeee" size="14"></u-icon>
								<text class="colorM font24 pl-1">{{item.viewing_count}}</text>
							</view>
							<view
								class="position-absolute flex justify-center align-center top-0 left-0 rounded-top-left-lg rounded-bottom-right-lg"
								style="background-color: #27C916;" v-if="item.is_vip=='2'">
								<text class="p-1 font28">{{$t('playlet.limited')}}</text>
							</view>
							<view v-if="item.is_vip=='1'"
								class="position-absolute flex justify-center align-center top-0 left-0 rounded-top-left-lg rounded-bottom-right-lg"
								style="background-image: linear-gradient(135deg, #DFB074 0%, #C39651 100%);">
								<text class="p-1 font28 yousheFont">{{$t('playlet.vip')}}</text>
							</view>
						</view>
						<view class="pt-1">
							<text class="ellipsis2 colorF font30">{{item.title}}</text>
							<text class="font26 ellipsis2 pt-1 color6"
								v-if="item.title.length<8">{{item.synopsis}}</text>
					<!-- 		<text class="ellipsis2"
								:class="{font32:item.title.length<7,font30:item.title.length>=7&&item.title.length<=14,font26:item.title.length>14}">{{item.title}}</text>
							<text class="font26 ellipsis2 pt-1 color6"
								v-if="item.title.length<8">{{item.synopsis}}</text> -->
						</view>
						<!-- 		<view class="content">
							<view class="title">
								{{item.title}}
							</view>
							<view class="desc">
								{{item.synopsis}}
							</view>
						</view> -->
					</view>
				</view>
			</view>
			<view class="search-list" v-else>
				<view class="title">
					{{$t('playlet.retrieved')}} {{total}}
				</view>
				<view class="" v-if="skeletonShow">
					<view class="item item1" v-for="item in 6" :key="item">
						<view class="image">
						</view>
						<view class="content">
							<view class="title">
							</view>
							<view class="desc">
							</view>
						</view>
					</view>
				</view>
				<view class="pt-5 empty" v-if="videoList.length==0">
					<u-empty :text="$t('public.nodata')" icon="/static/empty/nodata.png"></u-empty>
				</view>
				<view class="" v-else>
					<view class="item" @click="goShortInfo(item.id)" v-for="item in videoList">
						<view class="image">
							<image class="img" :src="item.img" alt="" />
							<view
								class="position-absolute flex justify-center align-center top-0 left-0 rounded-top-left-lg  rounded-bottom-right-lg"
								style="background-color: #27C916;" v-if="item.is_vip=='2'">
								<text class="p-1 font28">{{$t('playlet.limited')}}</text>
							</view>
							<view v-if="item.is_vip=='1'"
								class="position-absolute flex justify-center align-center top-0 left-0 rounded-top-left-lg rounded-bottom-right-lg"
								style="background-image: linear-gradient(135deg, #DFB074 0%, #C39651 100%);">
								<text class="p-1 font28 yousheFont">{{$t('playlet.vip')}}</text>
							</view>
							<view class="position-absolute bottom-0 left-0 right-0 flex align-center justify-end pr-1" style="height: 20px; background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.5) 100%);">
								<u-icon name="eye" color="#eeeeee" size="14"></u-icon>
								<text class="colorM font24 pl-1">{{item.viewing_count}}</text>
							</view>
						</view>
						<view class="content">
							<view class="title">
								{{$t('playlet.episode')}} 1
								<view class="separate">
									|
								</view>
								{{item.title}}
							</view>
							<view class="desc">
								{{item.synopsis}}
							</view>
							<view class="play">
								<view class="play-right" v-if="item.is_vip=='0'">
									<u-icon name="play-right" color="#fff" size="16"></u-icon>
								</view>
								<view class="play-right buy" v-else>
									{{$t('playlet.buy')}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-loadmore :status="loadStatus" :loadingText="loadingText" :loadmoreText="loadmoreText"
			:nomoreText="nomoreText" class="py-3" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				backShow: true,
				vipList: [{
						key: this.$t('playlet.free'),
						value: '0',
					},
					{
						key: this.$t('playlet.vip'),
						value: '1',
					}, {
						key: this.$t('playlet.le'),
						value: '2',
					}
				],
				sexList: [{
					key: this.$t('playlet.girl'),
					value: '0',
				}, {
					key: this.$t('playlet.male'),
					value: '1',
				}],
				orderList: [{
					key: this.$t('playlet.recommend'),
					value: '1',
				}, {
					key: this.$t('playlet.most'),
					value: '2',
				}],
				cateForm: {
					page: 1,
					limit: 9,
					title: '',
					vip: '',
					sex: '',
					order: '',
					type: ''
				},
				cateList: [],
				videoList: [],
				serachShow: false,
				loadStatus: 'nomore',
				loadingText: this.$t('load.loadingText'),
				loadmoreText: this.$t('load.loadmoreText'),
				nomoreText: this.$t('load.nomoreText'),
				total: 0,
				cateShow: true,
				skeletonShow: false
				// animationData: ''
			};
		},
		onReachBottom() {
			console.log("触底了");
			if (this.loadStatus !== "loadmore") return;
			this.loadStatus = "loading"
			this.cateForm.page++;
			this.handleVideoList()
		},
		onUnload() {
			// this.animationData = ''
		},
		onLoad() {
			this.videoList = []
			this.handleCateList()
			this.handleVideoList()
			// this.animation = uni.createAnimation({
			// 	duration: 4000,
			// 	timingFunction: "ease-in-out",
			// 	delay: 0
			// })
		},
		methods: {
			playVideo(item){
				console.log(111,item)
				uni.navigateTo({
					url:'/pages/playlet/episode?id='+item.id
				})
			},
			goShortInfo(id) {
				uni.navigateTo({
					url: "/pages/playlet/shortInfo?id=" + id
				})
			},
			handleUpdatForm(key, value) {
				this.cateForm[key] = value
				this.videoList = []
				this.handleVideoList()
				// console.log(this.cateForm, 'this.cateForm')
			},
			handleCateList() {
				this.$api.search.getVideoTypeList().then(res => {
					console.log(res, '分类')
					this.cateList = res.data
				})
			},
			handleCateShow() {
				this.cateShow = !this.cateShow
				// this.animation.height(0).step()
				// this.animationData = this.animation.export()
			},
			handleVideoList() {
				this.skeletonShow = true
				this.total = 0
				console.log("请求列表参数：",this.cateForm);
				this.$api.search.getVideoList(this.cateForm).then(res => {
					console.log("请求列表返回：",res);
					this.total = res.data.total
					this.skeletonShow = false
					this.loadStatus = res.data.list.length < this.cateForm.limit ? 'nomore' : 'loadmore'
					this.videoList = [...this.videoList, ...res.data.list]
					// console.log(this.videoList, ...res.data.list)
					// this.videoList = res.data.list
				})
			},
			goBack() {
				if (!this.serachShow) {
					uni.navigateBack()
				} else {
					this.serachShow = false
					this.cateShow = true
					this.form.title=""
					uni.pageScrollTo({
						selector: '.cate',
						duration: 300
					})
				}

			},
			handleSearch() {
				this.serachShow = true
				this.cateShow = false
				this.videoList = []
				this.cateForm = {
					page: 1,
					limit: this.cateForm.limit,
					title: this.cateForm.title,
					vip: '',
					sex: '',
					order: '',
					type: ''
				}
				this.handleVideoList()
				uni.pageScrollTo({
					selector: '.search-list',
					duration: 300
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.uni-input {
		height: 35px;
		padding-left: 10px;
		width: calc(100% - 53px);
		background-color: #161616;
	}

	.searchIcon {
		width: 40px;
		display: flex;
		height: 35px;
		align-items: center;
		justify-content: center;
		background-color: #161616;
	}

	.back {
		width: 20px;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-right: 10px;
	}

	.right {
		width: 30px;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-right: 10px;
	}

	.playlet-search {
		.search {
			display: flex;
			align-items: center;
			justify-content: flex-end;
			width: 100%;
			padding: 10px 0;
			position: fixed;
			left: 0;
			top: 0;
			background-color: #080808;
			z-index: 5;

			.back {
				width: 50px;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.input {
				background-color: #1d1d1d;
				width: calc(100% - 100px);
				display: flex;
				align-items: center;
				justify-content: center;

				.uni-input {
					height: 35px;
					padding-left: 10px;
					width: calc(100% - 40px);
					background-color: #161616;
				}

				.searchIcon {
					width: 40px;
					display: flex;
					height: 35px;
					align-items: center;
					justify-content: center;
					background-color: #161616;
				}
			}

			.right {
				width: 50px;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}

	}

	.cate-list {
		// margin-top: 55px;
		background-color: #080808;

		.cate {
			padding: 0 14px;

			.item {
				display: flex;
				align-items: flex-start;
				font-size: 14px;

				.all {
					background-color: #1d1d1d;
					padding: 7px 14px;
					border-radius: 6px;
				    white-space: nowrap;
				}


				.active {
					background-color: #27c916;
				}

				.key {
					display: flex;
					margin-left: 10px;
					width: calc(100% - 10px);
					flex-wrap: wrap;

					.value {
						background-color: #1d1d1d;
						padding: 8px 13px;
						border-radius: 6px;
						margin-right: 10px;
						margin-bottom: 10px;
					}

					.active {
						background-color: #27c916;
					}
				}

			}

		}

		.cate-video {
			padding: 0 14px;
			padding-bottom: 0;

			.empty {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 100%;
			}

			>view {
				width: 100%;
				display: flex;
				flex-wrap: wrap;
				justify-content: flex-start;
			}

			.video-item {
				width: calc(33.3% - 10px);
				margin-bottom: 20px;
				margin-right: 15px;

				.image {
					width: 100%;
					height: 170px;
					background-color: rgba(255, 255, 255, 0.5);
					border-radius: 6px;
					position: relative;

					.img {
						width: 100%;
						height: 100%;
						border-radius: 6px;
					}

					.episode {
						position: absolute;
						bottom: 5px;
						right: 5px;
						font-family: PingFangSC-Regular;
						font-size: 8px;
						// z-index: 2;
					}
				}

				.content {
					margin-top: 10px;
					font-size: 12px;

					.title {
						font-size: 14px;
						color: #FFFFFF;
						// letter-spacing: 0.39px;
						font-weight: 700;
						white-space: nowrap;
						/* 确保文本在一行内显示 */
						overflow: hidden;
						/* 隐藏超出容器的内容 */
						text-overflow: ellipsis;
						/* 使用省略号表示被截断的文本 */
					}

					.desc {
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: normal;
					}
				}
			}
		}
	}

	.py-3 {
		margin-top: 0 !important;
		// padding-top: 0 ;
		background-color: #080808 !important;
	}

	.search-list {
		// margin-top: 55px;
		padding: 10px 14px;

		.title {
			margin-bottom: 22px;
			font-size: 20px;
			color: #FFFFFF;
			font-weight: 700;
		}

		.item {
			height: 110px;
			margin-bottom: 10px;
			display: flex;

			.image {
				height: 100%;
				width: 80px;
				margin-right: 13px;
				position: relative;

				.img {
					width: 100%;
					height: 100%;
					border-radius: 6px;
				}

				.episode {
					position: absolute;
					bottom: 5px;
					font-family: PingFangSC-Regular;
					font-size: 8px;
					left: 10%;
				}
			}

			.content {
				// margin-top: 10px;
				font-size: 12px;
				width: calc(100% - 87px);

				.title {
					font-size: 14px;
					color: #FFFFFF;
					// letter-spacing: 0.39px;
					font-weight: 700;
					white-space: nowrap;
					/* 确保文本在一行内显示 */
					overflow: hidden;
					/* 隐藏超出容器的内容 */
					text-overflow: ellipsis;
					display: flex;
					margin-bottom: 3px;

					/* 使用省略号表示被截断的文本 */
					.separate {
						margin: 0 5px;
						font-weight: 400;
						color: #666;
					}
				}

				.desc {
					color: #444;
					line-height: 2em;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: normal;
					font-size: 12px;
					height: 4em;
				}

				.play {
					display: flex;
					margin-top: 10px;

					.play-right {
						border-radius: 6px;
						width: 62px;
						height: 32px;
						display: flex;
						align-items: center;
						justify-content: center;
						background-color: #27c916;
						margin-right: 10px;
					}

					.buy {
						font-size: 14px;
						background-color: #ED3737;
					}
				}
			}
		}

		.item1 {
			.image {
				background-color: rgba(255, 255, 255, 0.5);
				border-radius: 6px;
			}

			.title {
				height: 1.5em;
				background-color: rgba(255, 255, 255, 0.5);
				border-radius: 2px;
			}

			.desc {
				height: 6em;
				background-color: rgba(255, 255, 255, 0.5);
				border-radius: 2px;
			}
		}
	}
</style>